import { IPublicModelPluginContext } from '@alilc/lowcode-types';
import { Button } from '@alifd/next';
import {
  resetSchema,
  updatePageInfo
} from '../../services/pageManage';
import { config } from '@alilc/lowcode-engine';
import { useEffect } from 'react';

// 保存功能示例
const SaveSamplePlugin = (ctx: IPublicModelPluginContext) => {
  return {
    async init() {
      const { skeleton, hotkey, config } = ctx;
      const scenarioName = config.get('scenarioName');

      skeleton.add({
        name: 'saveSample',
        area: 'topArea',
        type: 'Widget',
        props: {
          align: 'right',
        },
        content: (
          <Button type="primary" onClick={updatePageInfo}>
            保存
          </Button>
        ),
      });
      // skeleton.add({
      //   name: 'resetSchema',
      //   area: 'topArea',
      //   type: 'Widget',
      //   props: {
      //     align: 'right',
      //   },
      //   content: (
      //     <Button onClick={() => resetSchema(scenarioName)}>
      //       重置页面
      //     </Button>
      //   ),
      // });
      hotkey.bind('command+s', (e) => {
        e.preventDefault();
        updatePageInfo();
      });
    },
  };
}
SaveSamplePlugin.pluginName = 'SaveSamplePlugin';
SaveSamplePlugin.meta = {
  dependencies: ['EditorInitPlugin'],
};
export default SaveSamplePlugin;